package top.zywork.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.zywork.common.BeanUtils;
import top.zywork.dao.GoodsInfoSkuPicDAO;
import top.zywork.dos.GoodsInfoSkuPicDO;
import top.zywork.dto.GoodsInfoSkuPicDTO;
import top.zywork.dto.PagerDTO;
import top.zywork.service.AbstractBaseService;
import top.zywork.service.GoodsInfoSkuPicService;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * GoodsInfoSkuPicServiceImpl服务接口实现类<br/>
 *
 * 创建于2019-07-12<br/>
 *
 * @author http://zywork.top 王振宇
 * @version 1.0
 */
@Service(value = "goodsInfoSkuPicService")
public class GoodsInfoSkuPicServiceImpl extends AbstractBaseService implements GoodsInfoSkuPicService {

    private GoodsInfoSkuPicDAO goodsInfoSkuPicDAO;

    @Override
    public PagerDTO listGoodsSkuByCondition(Long categoryId, Object queryObj) {
        PagerDTO pagerDTO = new PagerDTO();
        Long count = goodsInfoSkuPicDAO.countGoodsSkuByCondition(categoryId, queryObj);
        pagerDTO.setTotal(count);
        if (count > 0) {
            List<Object> doObjList = goodsInfoSkuPicDAO.listGoodsSkuByCondition(categoryId, queryObj);
            pagerDTO.setRows(BeanUtils.copyList(doObjList, GoodsInfoSkuPicDTO.class));
        } else {
            pagerDTO.setRows(new ArrayList<>());
        }
        return pagerDTO;
    }

    @Override
    public PagerDTO listHotGoodsSkuByCondition(Object queryObj) {
        PagerDTO pagerDTO = new PagerDTO();
        Long count = goodsInfoSkuPicDAO.countHotGoodsSkuByCondition(queryObj);
        pagerDTO.setTotal(count);
        if (count > 0) {
            List<Object> doObjList = goodsInfoSkuPicDAO.listHotGoodsSkuByCondition(queryObj);
            pagerDTO.setRows(BeanUtils.copyList(doObjList, GoodsInfoSkuPicDTO.class));
        } else {
            pagerDTO.setRows(new ArrayList<>());
        }
        return pagerDTO;
    }

    @Override
    public PagerDTO listAgentGoodsSkuByCondition(Object queryObj) {
        PagerDTO pagerDTO = new PagerDTO();
        Long count = goodsInfoSkuPicDAO.countAgentGoodsSkuByCondition(queryObj);
        pagerDTO.setTotal(count);
        if (count > 0) {
            List<Object> doObjList = goodsInfoSkuPicDAO.listAgentGoodsSkuByCondition(queryObj);
            pagerDTO.setRows(BeanUtils.copyList(doObjList, GoodsInfoSkuPicDTO.class));
        } else {
            pagerDTO.setRows(new ArrayList<>());
        }
        return pagerDTO;
    }

    @Override
    public PagerDTO listCategoryGoodsSkuByCondition(Long categoryId, Object queryObj) {
        PagerDTO pagerDTO = new PagerDTO();
        Long count = goodsInfoSkuPicDAO.countCategoryGoodsSkuByCondition(categoryId, queryObj);
        pagerDTO.setTotal(count);
        if (count > 0) {
            List<Object> doObjList = goodsInfoSkuPicDAO.listCategoryGoodsSkuByCondition(categoryId, queryObj);
            pagerDTO.setRows(BeanUtils.copyList(doObjList, GoodsInfoSkuPicDTO.class));
        } else {
            pagerDTO.setRows(new ArrayList<>());
        }
        return pagerDTO;
    }

    @Override
    public PagerDTO listAllGoodsSkuByCondition(Object queryObj) {
        PagerDTO pagerDTO = new PagerDTO();
        Long count = goodsInfoSkuPicDAO.countAllGoodsSkuByCondition(queryObj);
        pagerDTO.setTotal(count);
        if (count > 0) {
            List<Object> doObjList = goodsInfoSkuPicDAO.listAllGoodsSkuByCondition(queryObj);
            pagerDTO.setRows(BeanUtils.copyList(doObjList, GoodsInfoSkuPicDTO.class));
        } else {
            pagerDTO.setRows(new ArrayList<>());
        }
        return pagerDTO;
    }

    @Autowired
    public void setGoodsInfoSkuPicDAO(GoodsInfoSkuPicDAO goodsInfoSkuPicDAO) {
        super.setBaseDAO(goodsInfoSkuPicDAO);
        this.goodsInfoSkuPicDAO = goodsInfoSkuPicDAO;
    }

    @PostConstruct
    public void init() {
        super.init(GoodsInfoSkuPicDO.class, GoodsInfoSkuPicDTO.class);
    }
}
